<?php

class MemberView {
	private $m_firstName = "firstName";
	private $m_ssn = "ssn";
	private $m_numberOfBoats = "numberOfBoats";
	private $m_registerMember = "registerMemeber";
	private $m_deleteMember = "deleteMember";
	//AddMember
	private $m_AddMember = "AddMember";
	private $m_addBoat = "addBoat";
	private $m_boatInfo = "boatInfo";
	//Updateboat
	private $m_boatType = "boatType";
	private $m_boatTypeId = "boatTypeId";
    private $m_memberId = "memberId";
    private $m_boatId = "boatId";
    private $m_editBoat = "editBoat";
	private $m_boatLength = "boatLength";
	private $m_searchButton = "searchButton";
	private $m_searchFor = "searchFor";
	
	const SEARCH_ALTERNATIVE = "searchAlternative";
	const BOATINFO = "boatInfo";
	const BOATTYPE = "boatType";
	const BOATLENGTH = "boatLength";
	const MEMBERNAME = "memberName";
	const MEMBERSSN = "memberSsn";

	public function registerMemberForm () {
		return "<p>Fyll i användaruppgifter:</p>
			<form action='' method='post'>
			<p>Förnamn: <input type = 'text' name = '$this->m_firstName'/> </p>
			<p>Personnummer: <input type='text' name ='$this->m_ssn'/></p>
			<p>Antal båtar: <input type='text' name ='$this->m_numberOfBoats'/></p>
			<input type='submit' name='$this->m_registerMember' value = 'Registrera medlem'/>
		</form>
		";
	}
	
	public function SearchBox (){
		return "
			<form action='' method='post'>
			<input type = 'text' name = '$this->m_searchFor'/> 
			<input type='submit' name='$this->m_searchButton' value = 'Sök'/></br>
			<p>Sök bland</p>
			<input type='radio' name='".self::SEARCH_ALTERNATIVE."' value='".self::BOATINFO."' /> Båtinfo<br />
			<input type='radio' name='".self::SEARCH_ALTERNATIVE."' value='".self::BOATTYPE."' /> Båttyp
			<input type='radio' name='".self::SEARCH_ALTERNATIVE."' value='".self::BOATLENGTH."' /> Båtlängd<br />
			<input type='radio' name='".self::SEARCH_ALTERNATIVE."' value='".self::MEMBERNAME."' /> Medlemsnamn
			<input type='radio' name='".self::SEARCH_ALTERNATIVE."' value='".self::MEMBERSSN."' /> Medlems personnummer<br />
		</form>
		";
	}
	
	public function TriedToSearch (){
		if(isset($_POST[$this->m_searchButton])){
			return true;
		}else{
			return false;
		}
	}	
	
	public function GetSearchWord (){
		return $_POST[$this->m_searchFor];
	}

    public function EditBoat($a_boatTypes){
            	$ret = "";
                $ret .= "<h2>Ändra dina båtar</h2>
                		<p>Fyll i det som ska ändras:</p>
                        <form action='' method='post'>
                        <p>Båtinfo: <input type = 'text' name = '$this->m_boatInfo'/></p>      
                        <span>Välj båttyp: </span><select name='$this->m_boatTypeId'>";
				
						foreach($a_boatTypes as $boattype){
							$ret .= "<option value='".$boattype['boatTypeId']."''.>".$boattype['boatType']."</option>";
						}
						$ret .="</select>
                        <p>Båtlängd: <input type='text' name ='$this->m_boatLength'/></p>
                        <p>Membersnummer: <input type='text' name ='$this->m_memberId'/></p>
                        <p>Båtplats (båtid): <input type='text' name ='$this->m_boatId'/></p>
                        <input type='submit' name='$this->m_editBoat' value = 'Ändra båt'/>
                		</form>";
                return $ret;
                }

	public function RenderCompactMemberList($a_memberObject){
			$ret = "";
			
			foreach($a_memberObject as $key => $value){
				$ret .= "<h2>".$value->m_firstName."</h2>
						<p>Medlemsnummer: ".$value->m_memberId."</p>
						<p>Antal båtar: ".$value->m_numberOfBoats."</p>";
			}
			
			return $ret;
	}

	public function RenderMemberList($a_members, $a_boatInfo){
		$ret = "<table border=1>";
		$i = 0;
		foreach($a_members as $key => $value){
			$i= 0;
			$ret .= "<tr><td class='bold'>Medlemnr:</td> <td class='bold'>". $value->m_memberId."</td></tr> <tr><td>Namn:<td> ". $value->m_firstName."</td></tr>
			 <tr><td>personnummer:</td> <td>". $value->m_ssn."</td></tr>";
			

			foreach ($a_boatInfo as $boatInfoKey => $boatInfoValue){
				
				$ret .= "<ul>";
				if($value->m_memberId == $boatInfoValue->m_memberId) {
					$i++;
					$ret .= "
							<tr><td>Båt nr</td><td>".$i."</td></tr>
							<tr><td>Båttyp:</td> <td>".$boatInfoValue->m_boatType."</td></tr>
							<tr><td>Båtlängd:</td> <td>".$boatInfoValue->m_boatLength."</td></tr>
							<tr><td>Båtbeskrivning:</td><td> " . $boatInfoValue->m_boatInfo."</td></tr>";
				}
				$ret .= "</ul>";
			}
		}
		$ret .= "</ul>";
		return $ret;
	}
	
	
	public function DeleteMemberForm (){
		return"<h2>Ta bort medlem</h2><form action='' method='post'>
			<p>Förnamn: <input type = 'text' name = '$this->m_firstName'/> </p>
			<p>Personnummer: <input type='text' name ='$this->m_ssn'/></p>
			<input type='submit' name='$this->m_deleteMember' value = 'Ta bort medlem'/>
		</form>";
	}
	/*
	 * @Detta kommer att vara AddmembersView
	 * 
	 */
	
	public function AddMember(){
	return"<h2>Lägg till medlem</h2><form action='' method='post'>
			<p>Förnamn: <input type = 'text' name = '$this->m_firstName'/> </p>
			<p>Personnummer: <input type='text' name ='$this->m_ssn'/></p>
			<input type='submit' name='$this->m_AddMember' value = 'Lägg till medlem'/>
		</form>";
		
	}
	
	public function AddBoatToMember($a_boatTypes){
		$ret = "";
		$ret .= "<h2>Lägg till båt till medlem</h2>
				<form action='' method='post'>
				<p>Medlemsnummer: <input type='text' name ='$this->m_memberId'/></p>
				<p>Båtinfo: <input type='text' name ='$this->m_boatInfo'/></p>
				<p>Längd: <input type='text' name ='$this->m_boatLength'/></p>
				<select name='$this->m_boatTypeId'>";
				
				foreach($a_boatTypes as $boattype){
					$ret .= "<option value='".$boattype['boatTypeId']."''.>".$boattype['boatType']."</option>";
				}
		$ret .="</select>
				<input type='submit' name='$this->m_addBoat' value = 'Lägg till båt'/>
			</form>";
		
		return $ret;
	}
	
	public function GetFirstName(){
		return $_POST[$this->m_firstName];
	}
	
	public function GetSsn() {
		return $_POST[$this->m_ssn];
	}
	
	public function GetBoatTypeId (){
		return $_POST[$this->m_boatTypeId];
	}
	
	public function GetBoatLength(){
		return $_POST[$this->m_boatLength];
	}
	
	public function TriedToDeleteMember(){
		if(isset($_POST[$this->m_deleteMember])){
			return true;
		}else{
			return false;
		}
	}
	
	public function TriedToAddBoatToMember (){
		if(isset($_POST[$this->m_addBoat])){
			return true;
		}else{
			return false;
		}
	}
	
	public function TriedToAddMember(){
		if(isset($_POST[$this->m_AddMember])){
			return TRUE;
		}else{
			return FALSE;
		}	
	}
	 public function TriedToEditBoat(){
		if(isset($_POST[$this->m_editBoat])){
			return TRUE;	 		
			}
			return FALSE;	
		} 

	public function GetBoatType(){
		return $_POST[$this->m_boatType];
		
	}
	  public function GetBoatInfo(){
		return $_POST[$this->m_boatInfo];
	}
	  public function GetMemberId(){
		return $_POST[$this->m_memberId];
	}
	   public function GetBoatId(){
		return $_POST[$this->m_boatId];
			
	} 
	
}